home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FishMarket 1.0
/
FishMarket v1.0.iso
/
fishies
/
376-400
/
disk_388
/
calc
/
calc.doc
< prev
next >
Wrap
Text File
|
1992-05-06
|
19KB
|
397 lines
#3zq(Bpw
v"z
CALC 2.0 by Bill Dimm
Amiga Version August 7, 1990
The Amiga version of Calc may be distributed freely as long as no
charge beyond a reasonable copying fee is made. This program is
shareware - if you like it, you are encouraged to send me (a starving
grad student :-) ) a donation. If you have any bugs to report, or any
requests for features for the next version, please send them also.
Bill Dimm
Box 385
Springfield, PA. 19064-0385
DIMM@ANLPNS.BITNET
DIMM@ANLPNS.PNS.ANL.GOV
USAGE
Usage1: CALC [options]
Usage2: CALC [options] expression1 expression2 ...
Usage3: CALC [options] -v var expression [file1 file2 ...]
DESCRIPTION
Calc is a shell style calculator. Calc does not have a fancy
keypad display as many other calculator programs do. Instead, it is
capable of taking its input from a file, the keyboard (stdin), or a
command line and outputting its results to a file or the screen
(stdout). It can also apply a single equation to all of the values
stored in a file (or files). It handles all common mathematical
expressions, can optionally predefine physical constants (see the
options
-m
and
-g
and the commands
mks
and
gaussian
), and allows you to
store values in the 26 variables a-z.
If Calc is invoked using the format in Usage1, it will read
mathematical expressions and commands from the keyboard or the input
file (see option
-i
and command
infile
) and execute them until it
encounters the
exit
command, or finds the end of the input file. If
Calc is reading from the keyboard, it will display a prompt
CALC>
when
it is waiting for a command or mathematical expression. The command or
expression is evaluated when the return key is pressed. Expressions
may be of any length, and case is ignored. The result of the
evaluation of all mathematical expressions is displayed on the screen,
or stored in a file (see option
-o
and the command
outfile
). When an
error occurs, an error message is printed to the screen, or to a file
(see option
-e
and the command
errorfile
), and Calc ignores the rest of
the line and continues (unless the error is critical, in which case it
exits). Calc can be told to exit automatically when any error occurs
(see option
-a
and command
aborterron
). Comments can be added to a
line by preceding them with a
#
. All input is buffered (unless
buffering is turned off using the option
-b
or the command
bufferoff
)
so that you can save your work at any point by using the
save
command.
The format in Usage2 tells Calc to evaluate the
commands/expressions on the command line instead of reading a file or
the keyboard for commands/expressions. The commands/expressions used
in this mode are not buffered, so they cannot be saved.
Using Usage3 puts Calc in column mode. In this mode it will
Page 1
evaluate the given expression once for each value stored in the
specified files.
var
tells Calc what variable name to assign to the
values in
file1
.
var
must be a single alphabetic character. The next
alphabetic letter is assigned to the contents of
file2
, etc. If no
files are specified, values are read from the keyboard (stdin) and
assigned to
var
(you must terminate the input with an end of file which
is generated by typing
CTRL Z
on VMS). Calc reads a value from each of
the files, sets the corresponding variable, then evaluates the
expression, and outputs the result. This process is repeated until
Calc finds the end of one of the input files. Each value in the files
must be separated from the others by whitespace (spaces, tabs, or
carriage returns).
MATHEMATICAL EXPRESSIONS
Expressions conform to normal mathematical notation (note: you
must use a
*
for multiplication, you cannot simply use parenthesis).
They may be of any length, and case is ignored. All spaces and tabs
are ignored. You can also store the results of a calculation by typing
var=expression
where
var
is any letter from a to z. For example,
x = 4*sin(pi/3)/cosh(gamma(5))
Calc keeps track of the current value of each of the 26 variables, and
the expressions which were used to define them. Normally, when a
variable is defined, the expression is evaluated immediately and the
result is stored as the current value of the variable. Calc can be
told not to evaluate the expression immediately by using the
-d
or the
command
definitionevaloff
. You may use any of the 26 variables in a
mathematical expression. If you use a variable which has not been
defined, a warning is printed and the value 0 is used. When a variable
is used in an expression, Calc checks the definition of the variable
and automatically updates the current value of the variable if
necessary. For example:
CALC>
x=1 # This is a comment.
1
CALC>
y=2
2
CALC>
r=sqrt(x^2+y^2)
2.236067977499789
CALC>
1/r
0.447213595499958
CALC>
x=2
2
CALC>
1/r
0.353553390593274
When a variable's definition includes a reference to itself, it's
current value is used to compute a new value. For example:
CALC>
x=1
1
CALC>
x=x+.5
1.5
CALC>
x
2
CALC>
x
2.5
To list the definitions and current values of all variables, use the
list
command. The following is a list of expressions which are
supported by the FUNC library, which is responsible for evaluating
Page 2
mathematical expressions in Calc. Any required explanation of the
function/operator/constant is given. 'x' and 'y' are used to represent
any legal expressions (or constants). All angles are in radians.
x-y
Binary minus
-x
Unary minus
x+y
Binary plus
x%y
Modulus - gives the remainder that results from
dividing x by y
x&y
Logical AND - returns 1 if absolute value of
both x & y is > EPS (ie. x and y are non-zero). 0 is
returned otherwise.
x*y
Product of x and y
x/y
x divided by y
x<y
Returns 1 if x < y and 0 if x >= y
x=y
Returns 1 if the difference between x and y is < EPS
x>y
Returns 1 if x > y and 0 if x <= y
x^y
Gives x raised to the power y
abs(x)
Absolute value
acos(x)
Inverse cosine of x
acosh(x)
Inverse hyperbolic cosine
acot(x)
Inverse cotangent
acoth(x)
Inverse hyperbolic cotangent
acsc(x)
Inverse cosecant
acsch(x)
Inverse hyperbolic cosecant
asec(x)
Inverse secant
asin(x)
Inverse sine
asinh(x)
Inverse hyperbolic sine
atan(x)
Inverse tangent
cos(x)
Cosine
cosh(x)
Hyperbolic cosine
cot(x)
Cotangent
coth(x)
Hyperbolic cotangent
csc(x)
Cosecant
csch(x)
Hyperbolic cosecant
eps
Epsilon - a small number
exp(x)
Exponential: exp(x) = e^x
gamma(x)
Gamma function: gamma(x) = integral from t = 0 to infinity
of t^(x-1)exp(-t)dt. Note that for positive integers,
gamma(n+1) = n factorial, also denoted n!. Due to the fact
that gamma(x) is computed by different methods for
different values of x, gamma(x) may be discontinuous in
places.
lg(x)
Base 2 logarithm
ln(x)
Natural logarithm (base e)
log(x)
Base 10 logarithm
pi
Pi
sec(x)
Secant
sech(x)
Hyperbolic secant
sin(x)
Sine
sinh(x)
Hyperbolic sine
sqr(x)
x squared (x*x)
sqrt(x)
Square root
tan(x)
Tangent
tanh(x)
Hyperbolic tangent
x|y
Logical OR. Gives 1 if the absolute value of either
x or y is > eps. Gives 0 otherwise.
Page 3
Note that there is some ambiguity about an expression such as
x=2
. Is
this a definition, or an application of the equality operator? If Calc
finds a variable as the first character on a line, and an
=
following
it, it assumes that it is a definition. Thus, to force it to view the
=
as an equality operator instead of a definition, you could use
(x=2)
.
COMMANDS
The following commands are recognized by Calc.
aborterroff
Tells Calc not to abort when it is capable of recovering
from an error (this is the default).
aborterron
Tells Calc to abort when ANY error occurs.
bufferoff
Turns off the buffering of user input. Previously buffered
input is not lost. The
save
command only saves input which has been
buffered.
bufferon
Turns the buffering of user input on (this is the default).
The
save
command only saves input which has been buffered.
definitionevaloff
Causes calc not to immediately update a variable when it is
defined. This is useful when the definition relies on variables which
have not been defined yet.
definitionevalon
Causes Calc to evaluate variable definitions immediately &
update the current value of the variable (this is the default).
errfile
Prompts for the name of a file in which all error messages
are deposited.
exit
Exits from Calc.
gaussian
Defines several of the variables with useful constants in
the gaussian (centimeter, gram, second) system of units. Be warned
that previous definitions of these variables will be destroyed.
infile
Prompts for the name of a file which will be used for
input.
list
Lists the current values and definitions of all variables.
Page 4
mks
Defines several of the variables with useful constants in
the mks (meter, kilogram, second) system of units. Be warned that
previous definitions of these variables will be destroyed.
outfile
Prompts for the name of a file in which output is stored.
promptoff
Discontinues the displaying of
CALC>
when waiting for
commands/expressions from the keyboard (stdin).
prompton
Tells Calc to display the prompt
CALC>
when it is waiting
for commands/expressions from the keyboard (stdin). This is the
default.
quit
Same as
exit
.
repeatoff
Tells Calc not to echo the input to the output channel
(this is the default).
repeaton
Tells Calc to echo the input to the output channel. This
is useful when the output is being directed to a file so that you can
see both the expressions and their values.
save
Prompts for the name of a file in which the
commands/expressions which have been entered previously are stored.
OPTIONS
-o NAME
Stores all output in a file called
NAME
.
-i NAME
Uses the contents of the file
NAME
as input.
-e NAME
Stores all error messages in the file
NAME
.
-a
Same as the command
aborterron
.
-b
Same as the command
bufferoff
.
-d
Same as the command
definitionevaloff
.
-g
Same as the command
gaussian
.
Page 5
-m
Same as the command
mks
.
-p
Same as the command
promptoff
.
-r
Same as the command
repeaton
.
EXAMPLES
An example of Usage1:
$
CALC
CALC>
x=5
5
CALC>
y=2
2
CALC>
sin(x)*y^4
-15.342788394610217
CALC>
exit
An example of Usage2:
$
CALC 1+2/3 4/5 pi
1.666666666666667
0.8
3.141592653589793
As an example of Usage3, consider the two files:
file1:
1
2
3
4
file2:
2
2.5
3
3.5
Then, envoking calc as follows:
$
CALC -v x x^y file1 file2
1
5.656854249492377
27
127.9999999999999
Page 6